stage.set_background("schoolentrance")
stage.wait(2)
stage.create_grid_overlay(50, "blue")
stage.set_background_color("azure")
emma = codesters.Sprite("person1")
emma.set_size(0.5)
michael = codesters.Sprite("person2")
michael.set_size(0.5)
emma_x = random.randint(-230,230)
emma_y = random.randint(-230,230)
emma.go_to(emma_x, emma_y)
michael_x = random.randint(-230,230)
michael_y = random.randint(-230,230)
michael.go_to(michael_x, michael_y)
delta_x = emma_x - michael_x
delta_y = emma_y - michael_y
distance = math.sqrt((delta_x**2) + (delta_y**2))
t = codesters.Teacher()
say_cmd = t.find_text('emma.say')
says = t.get_parameters_for_function("say")
try:
params = t.find_block('if')
tval1 = params[0][1]
except:
tval1 = "DNE"
try:
tval2 = distance
except:
tval2 = "DNE"
try:
say_line = say_cmd[0][0]
tval3 = t.get_indent_at_line(say_line)
except:
tval3 = "DNE"
try:
tval4 = say_cmd[0][1]
except:
tval4 = "DNE"
t1 = TestObjective()
t1.add_failure(tval2 == "DNE", "Did you delete your distance formula?")
t1.add_success('"distance"' in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add an if statement?")
t2 = TestObjective()
t2.add_success("emma" in tval4, "Great job!")
t2.add_failure("emma" not in tval4, "Did you change the variable in front of the say command to emma?")
t2.add_failure(tval4 == "DNE", "Did you add a say command?")
t3 = TestObjective()
t3.add_success(tval3 == 4, "Great job!")
t3.add_failure(tval3 == 0, "Did you put the say command inside the if statement?")
t3.add_failure(tval3 == "DNE", "Did you add a say command in the if statement?")
t3.add_failure(tval3 > 4, "I think you indented your say command too far.")
tester = TestManager()
tester.add_test_list([t1,t2,t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)